using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace DataContext
{
	public class UserContext
	{
		#region Fields
		Database.Database db = new Database.Database(Database.Providers.SqlClient, Config.Global.Settings.ConnectionString);
		#endregion

		#region Constructors
		public UserContext() {}
		#endregion

        #region Context Methods        
        /// <summary>
        /// Check Login
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns>#0: Success</returns>
        public int CheckLogin(string userName, string password)
        {
            try
            {
                List<SqlParameter> lstParam = new List<SqlParameter>();
                lstParam.Add(new SqlParameter("@UserName", userName));
                lstParam.Add(new SqlParameter("@Password", password));

                return (int)db.ExecuteStoreProcedure("[uspUserCheckLogin]", lstParam.ToArray());
            }
            catch (System.Exception)
            {
                return 0;
            }
        }

        /// <summary>
        /// Check Exists UserName
        /// </summary>
        /// <param name="userName"></param>
        /// <returns>#0: Exists; 0: Didn't Exists</returns>
        public int CheckExistsUserName(string userName)
        {
            try
            {
                List<SqlParameter> lstParam = new List<SqlParameter>();
                lstParam.Add(new SqlParameter("@UserName", userName));

                return (int)db.ExecuteStoreProcedure("[uspUserCheckExistsUserName]", lstParam.ToArray());
            }
            catch (System.Exception)
            {
                return 0;
            }
        }

        /// <summary>
        /// Check Exists Email
        /// </summary>
        /// <param name="email"></param>
        /// <returns>#0: Exists; 0: Didn't Exists</returns>
        public int CheckExistsEmail(string email)
        {
            try
            {
                List<SqlParameter> lstParam = new List<SqlParameter>();
                lstParam.Add(new SqlParameter("@Email", email));

                return (int)db.ExecuteStoreProcedure("[uspUserCheckExistsEmail]", lstParam.ToArray());
            }
            catch (System.Exception)
            {
                return 0;
            }
        }

        /// <summary>
        /// Update User Status
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public bool UpdateStatus(int userID)
        {
            try
            {
                List<SqlParameter> lstParam = new List<SqlParameter>();
                lstParam.Add(new SqlParameter("@UserID", userID));

                db.ExecuteStoreProcedure("[uspUserUpdateStatus]", lstParam.ToArray());
                return true;
            }
            catch (System.Exception)
            {
                return false;
            }
        }
		#endregion
	}
}
